<?php namespace App\Http\Controllers\Site;

use App\Http\Controllers\Controller;
use App\Item;
use DB;

class NewsController extends Controller
{
    public function getIndex($kind='newest')
        //先默认为newest最新新闻
    {
        $data = Item::where('kind', $kind)->paginate( config('site.pageSize') );//config默认的是2；
        //获取data->按照items表下面kind字段查询，paginate是分页
        return view('site.News.index', [
            'data'=>$data,
            'param'=>['kind'=>$kind]
            //模版页面读取数据库存储的内容，
        ]);
    }
    public function getShow($id=0)
    {
        $data= Item::where('id',$id)->get();
        return view('site.News.show',[
            'data'=>$data,
            'param'=>['id'=>$id],
        ]);
    }
    //公司新闻
    public function getCom()
    {
        $data= Item::where('kind','companynews')->paginate( config('site.pageSize'));
        return view('site.News.com',[
            'data'=>$data,
            'param'=>['kind'=>'companynews'],
        ]);
    }

    //行业新闻
    public function getTrade ()
    {
       $data= Item::where('kind',$kind='businessnews')->paginate( config('site.pageSize') );
       return view('site.News.trade',[
           'data'=>$data,
           'param'=>['kind'=>$kind],
       ]);
     }

}